package ca.scotthyndman.as2haxe.dom.binding.impl;

import java.util.HashSet;
import java.util.Set;

import org.apache.log4j.Logger;

import ca.scotthyndman.as2haxe.dom.ASTNode;
import ca.scotthyndman.as2haxe.dom.binding.BindingManager;
import ca.scotthyndman.as2haxe.dom.binding.IBinding;

/**
 * Base class for bindings.
 */
public abstract class BindingBase implements IBinding {

	protected static final Logger log = Logger.getLogger(BindingBase.class);

	/** This binding's declaration node */
	private ASTNode node;

	/** The binding's unique key */
	private String key;

	/** Nodes referring to this binding */
	private Set<ASTNode> referringNodes = new HashSet<ASTNode>();

	/** The binding manager */
	protected BindingManager manager;

	/**
	 * Constructs a new binding base
	 * 
	 * @param node
	 * @param key
	 */
	public BindingBase(ASTNode node, String key) {
		this.node = node;
		this.key = key;
	}

	public ASTNode getASTNode() {
		return node;
	}

	public String getKey() {
		return key;
	}

	public void setKey(String key) {
		this.key = key;
	}

	public void setBindingManager(BindingManager mgr) {
		manager = mgr;
	}

	public Set<ASTNode> getReferringNodes() {
		return referringNodes;
	}

	@Override
	public String toString() {
		return "Binding(kind=" + getKind() + ", key=" + getKey() + ", node="
				+ getASTNode() + ")";
	}
}
